<template>
	<view class="content">
		<u-navbar title="主页" placeholder @leftClick="navBack">
			<view slot="center" class="title">主页</view>
			<!-- <u-icon  slot="right" size="55rpx" color="#0BB78E" name="search" @click="search"></u-icon> -->
			<view slot="right" @click="loginout">{{ accountName }}</view>
		</u-navbar>
		<view class="menu-item" @click="pageTo('1')">
			<view style="margin-left: 15px;">
				<u-image :src="icon2" width="45px" height="45px" mode="widthFix"></u-image>
			</view>
			<view style="letter-spacing: 5px; font-weight: bold; margin-left: 25px;">库存管理</view>
		</view>
		<view class="menu-item" @click="pageTo('2')">
			<view style="margin-left: 15px;">
				<u-image :src="icon1" width="50px" height="50px" mode="widthFix"></u-image>
			</view>
			<view style="letter-spacing: 5px; font-weight: bold; margin-left: 20px;">信息采集</view>
		</view>
		<view class="menu-item" @click="modifyInfo">
			<view style="margin-left: 15px;">
				<u-image :src="icon3" width="50px" height="50px" mode="widthFix"></u-image>
			</view>
			<view style="letter-spacing: 5px; font-weight: bold; margin-left: 20px;">修改资料</view>
		</view>
	</view>
</template>

<script>
import dayjs from 'dayjs'
import icon1 from '@/static/image/icon1.png'
import icon2 from '@/static/image/icon2.png'
import icon3 from '@/static/image/info.png'
export default {
	data() {
		return {
			icon1: icon1,
			icon2: icon2,
			icon3: icon3,
			accountName: ''
		}
	},
	onLoad(options) {
		let globalData = getApp({allowDefault: true}).globalData
		console.log(globalData)
		this.accountName = globalData.userName
	},
	methods: {
		pageTo(index) {
			let url
			if (index == '1') {
				url = '/pages/stock/stock'
			} else {
				url = '/pages/userList/userList'
			}
			uni.navigateTo({ url: url })
		},
		loginout() {
			uni.showModal({
				title: '提示',
				content: '是否退出登录？',
				showCancel: true,
				success: ({ confirm, cancel }) => {
					if (confirm) {
						uni.removeStorageSync('token')
						uni.redirectTo({ url: '/pages/login/login' })
					}
				}
			})
		},
		modifyInfo() {
			uni.navigateTo({ url: '/pages/signIn/signIn?modify=1' })
		},
	},
}
</script>

<style lang="stylus" scoped>
.menu-item
	margin 10px
	background #ffffff
	padding 10px
	font-size 16px
	text-align center
	display flex
	align-items center
	color hsl(206, 20, 50)
	border-radius 8px
</style>
